Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TxtSize As System.Windows.Forms.TextBox Friend WithEvents txtArea As System.Windows.Forms.TextBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtPerim As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents BtnCalc As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.TxtSize = New System.Windows.Forms.TextBox Me.txtArea = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.TxtPerim = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.BtnCalc = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(24, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(48, 32) Me.Label1.TabIndex = 0 Me.Label1.Text = "Size" ' 'TxtSize ' Me.TxtSize.Location = New System.Drawing.Point(80, 24) Me.TxtSize.Name = "TxtSize" Me.TxtSize.Size = New System.Drawing.Size(96, 20) Me.TxtSize.TabIndex = 1 Me.TxtSize.Text = "" ' 'txtArea ' Me.txtArea.Location = New System.Drawing.Point(88, 72) Me.txtArea.Name = "txtArea" Me.txtArea.ReadOnly = True Me.txtArea.Size = New System.Drawing.Size(96, 20) Me.txtArea.TabIndex = 3 Me.txtArea.Text = "" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(32, 72) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(48, 32) Me.Label2.TabIndex = 2 Me.Label2.Text = "Area" ' 'TxtPerim ' Me.TxtPerim.Location = New System.Drawing.Point(80, 112) Me.TxtPerim.Name = "TxtPerim" Me.TxtPerim.ReadOnly = True Me.TxtPerim.Size = New System.Drawing.Size(96, 20) Me.TxtPerim.TabIndex = 5 Me.TxtPerim.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(0, 112) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(72, 32) Me.Label3.TabIndex = 4 Me.Label3.Text = "Perimeter" ' 'BtnCalc ' Me.BtnCalc.Location = New System.Drawing.Point(200, 24) Me.BtnCalc.Name = "BtnCalc" Me.BtnCalc.Size = New System.Drawing.Size(64, 32) Me.BtnCalc.TabIndex = 6 Me.BtnCalc.Text = "Calculate" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.BtnCalc) Me.Controls.Add(Me.TxtPerim) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.txtArea) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.TxtSize) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim square1 As square square1 = New square(5) ' create a square (instantiate) MsgBox(square1.Length) square1.Length = 17 MsgBox(square1.Length) square1.Length = -17 MsgBox(square1.Length) Dim area As Double area = square1.calcArea() MsgBox("area: " & area) Dim square2 As square square2 = New square(-5) MsgBox(square2.Length) End Sub Private Sub BtnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalc.Click Dim square1 As square If IsNumeric(TxtSize.Text) Then Dim size = Convert.ToDouble(TxtSize.Text) If size > 0 Then square1 = New square(size) Dim area As Double = square1.calcArea() txtArea.Text = area.ToString("n1") Dim perim As Double perim = square1.calcPerimeter() TxtPerim.Text = perim.ToString("n1") End If End If End Sub End Class